import type { DescData } from '@arco-design/web-vue/es/descriptions/interface'
import axios from 'axios'
import qs from 'query-string'

export interface PageQuery{
  current: number
  pageSize: number
  name?: string
}

export interface CategoryRecord {
  id: number,
  name: string | null
  sort: number
  visibility: boolean
}

export interface CategoryPageRes{
  list: CategoryRecord[],
  total: number
}

export interface CategoryDetail extends CategoryRecord {
  id: number,
  name: string | null
  sort: number
  visibility: boolean
}

// 分页查询会员
export function queryCategoryPage(params: PageQuery) {
  return axios.get<CategoryPageRes>('/api/category/page',{
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj)
    },
  })
}

// 获取会员详情
export function getCategoryDetail(id: number) {
  return axios.get<CategoryDetail>(`/api/category/${id}`)
}

// 编辑会员信息
export function updateCategory(data: CategoryDetail) {
  return axios.put('/api/category', data)
}

// 删除会员
export function deleteCategory(ids: number[]) {
  return axios.delete('/api/category', {
    data: ids
  })
}